<!--
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File Upload</title>

<?php

if( $_FILES["uploadedFile"] != NULL) //new file is found
{
	$file_name = $_FILES["uploadedFile"]["name"];
	$tmp_file_name = $_FILES["uploadedFile"]["tmp_name"];
	
	$dest_path = $_POST["destination"];
	$dest = $dest_path."/".$file_name;
	copy($tmp_file_name, $dest);

	$server_msg = "new";
	$server_msg_param = $file_name;
}
?>

<script language="javascript">

function init()
{
	var serverMsg = document.getElementById('serverMsg');
	var serverMsgParam = document.getElementById('serverMsgParam');
	if (serverMsg.value == "new")
	{
		//informa parent
		parent.atNewFile(serverMsgParam.value);
	}
}

function uploadthis(ctrl)
{
	var fileName = ctrl.value;
	var selectedPath = "";
	if( parent.selectedId == -1 || parent.nodesArray[parent.selectedId].type == 0)
	{
		if ((/^.+\.swf$/.test(fileName)))
		{
			selectedPath = "../store/swf";
		}
		else if ((/^.+\.gif$/.test(fileName)) ||
			(/^.+\.jpg$/.test(fileName))||
			(/^.+\.png$/.test(fileName))
		)
		{
			selectedPath = "../store/images";
		}
		else
		{
			selectedPath = "../store/images";
		}
	}
	else
	{
		selectedPath = parent.nodesArray[parent.selectedId].path;
	}
	parent.selectedPath = selectedPath;
	
	var dest = document.getElementById('destination');
	dest.value = selectedPath;
	ctrl.form.submit();
}
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input name="uploadedFile" title="file to upload" onchange="uploadthis(this)" type="file" />
<input id="destination" type="hidden" value="" name="destination" />

<input id="serverMsg" type="hidden" value="<?php echo $server_msg; ?>" />
<input id="serverMsgParam" type="hidden" value="<?php echo $server_msg_param; ?>" />

</form>
<script>
init();
</script>
</body>
</html>
